POV-Ray : Newsgroups : povray.general : The Language of POV-Ray : Re: The Language of POV-Ray Server Time
10 Aug 2024 09:10:19 EDT (-0400)
  Re: The Language of POV-Ray  
From: Nick Drew
Date: 5 Apr 2000 10:21:23
Message: <38eb4be3@news.povray.org>
><snipped/>
>First let me say that I like XML (and I do hand-code it, and I also
>think that vi is the best HTML-editor), but I think that omitting the
>algorithmic elements of POV-Script in POVML (or whatever we would like
>to call it) would be a mistake.
>
>Consider this fragment of POV-Script:
>
>        #declare i = 0;
>        #while (i < 360)
>
>            object {
>                vesta
>                translate <830, 50+10, 0>
>                rotate <0, i, 0>
>            }
>
>            #declare i = i + 12;
>        #end
>
>This puts 30 "vesta" objects in a circle of 830 pov-units radius.
>
>If this would be converted to
>
>    <object name="vesta">
> <translate><vector>830 60 0</vector></translate>
> <rotate><vector>0, 0, 0</vector></rotate>
>    </object>
>    <object name="vesta">
> <translate><vector>830 60 0</vector></translate>
> <rotate><vector>0, 12, 0</vector></rotate>
>    </object>
>    .
>    .
>    .
>    <object name="vesta">
> <translate><vector>830 60 0</vector></translate>
> <rotate><vector>0, 348, 0</vector></rotate>
>    </object>
>
>It isn't a circle of objects any more. These are 30 independent objects
>which just happen to form a circle.
>
>I do admit that I would prefer something like
>
>    <loop start="0" end="348" step="12">
> ...
>    </loop>
>
>to
>
>    <set variable=i value="0" />
>    <while expr="i < 360">
> ...
> <set variable=i expr="i+12" />
>    </while>
>
>The latter doesn't really feel XMLish to me.
>

I agree.

How about a more declarative approach?  For simple loops where you can do
some range analysis (all tagnames/attributes are tentative):

    <forall subject="i" range="{0..360}">
<!--declare the range of i-->
        <where expr="i%12 == 0">
            <apply-in-sequence>
<!--not sure about this - see below-->
                <rotate>
                    <vector>0 <valueOf select="i"/> 0</vector>   <!--invoke
i within longhand rotate->
                </rotate>
                <transform t="t 830 60 0"/>
<!--use shorthand form where feasible
                <object use="vesta"/>
<!--assume vesta is mesh, as opposed to macro. see below-->
            </apply-in-sequence>
        </where>
    </forall>

The apply-in-sequence (or something like it) would be needed to avoid having
nested transforms like:

<rotate>
    <vector>...</vector>
    <transform t="...">
        <object .../>
    </transform>
</rotate>

This would be poor in the sense that the author could place the <vector> tag
pair after the <transform>.  To check for this the DOM traverser would have
to scan all children to extract the info it needed.  An event based XML
parser wouldn't be affected, though so the latter form is still viable.

I believe a suitable editor would be able to allow the user to edit this
shape by changing the expression in the <where> tag.  If you look at XSL,
they have the <xsl:choose> tag, which has <xsl:when> and <xsl:otherwise>
tags.  Take this idea and apply it to ranges of values rather than tag
patterns, and I think you've got a powerful

Macros are a bit trickier - to include a circle of circles you could a)
define a clause (a subroutine in procedural languages) which exposes a
variable, and then b) invoke the clause with a given range for the variable.

a)

    <clause name="vestaTwist">
        <expose subject="i" default-range="{0..360}"/>
        <forall subject="i">
            <where expr="i%12 == 0">
                <apply-in-sequence>
                    <rotate>
                        <vector>0 <valueOf select="i"/> 0</vector>
                    </rotate>
                    <transform t="t 830 60 0"/>
                    <object use="vesta"/>
                </apply-in-sequence>
            </where>
        </forall>
    </clause>

b)
    <forall subject="i" range="{0..360}">
      <where expr="i%12 == 0">
            <apply-in-sequence>
                <rotate>
                    <vector>0,<valueOf select="i"/>,0</vector>
                </rotate>
                <transform t="t <830,60,0>"/>
                <scale s="1/830 1/60 0"/>
                <eval name="vestaTwist">
                    <supply id="i" range="{0..90}"/>
                 </eval>
            </apply-in-sequence>
        </where>
    </forall>

Cheers,

Nick Drew

HyperSpace Ltd,Birmingham Research Park, Edgbaston, UK, B15 2SQ
(e) hyp### [at] btinternetcom           (t) +44 (0)121 414 7019


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.